package netty.high;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class HighServerHandler extends ChannelInboundHandlerAdapter
{
	@Override
	public void channelActive(final ChannelHandlerContext ctx) throws Exception
	{
		final ChannelFuture f = ctx.writeAndFlush("server's message");
		f.addListener(new ChannelFutureListener()
		{
			@Override
			public void operationComplete(ChannelFuture future)
			{
				ctx.close();
			}
		});
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
	{
		cause.printStackTrace();
		ctx.close();
	}
}
